package controllers;

import models.Idea;
import play.mvc.Controller;

public class Rating extends Controller {

	/**
	 * The below method is done to call the rate method in the Idea class in the
	 * models package and render the output of that rate method in the view
	 * along with the idea rated and the average rate.
	 * 
	 * @param ideaId
	 *            a Long id which is the idea id to be rated.
	 * 
	 *            @ author Ismail Omar
	 */
	public static void rateIdea(Long ideaId) {
		Idea i = Idea.findById(ideaId);
		String rateRadioButton = params.get("rate");
		int rateInput = Integer.parseInt(rateRadioButton);
		double average = i.rate(rateInput);
		i.save();
		render(i, rateInput, average);
	}
}
